package quantri.qlcn;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.faces.model.SelectItem;

import quantri.pqcn.User;
import dbutil.ConnectDB;

/******************************************
 * Filename			: ItemCollection.java
 * Decription		: Bean chứa danh sách các group và cat để hiển thị
 * Created date		: Jun 4, 2008
 * Author			: Phonglt
 ******************************************/
public class ItemCollection {
	private final String sql_groups = "SELECT fullname, id FROM nhomchucnang ORDER BY fullname";
	private final String sql_cats = "SELECT fullname, id FROM loaichucnang ORDER BY fullname";
	
	
	/**************************************
	 * Method name		: updateItems
	 * Return type		: List<SelectItem>
	 * Decription		: lấy ds SelectItem các cat, group từ DB
	 * Created date		: Jun 4, 2008
	 * Author			: Phonglt
	 * Modified			:Honglk
	 **************************************/
	private  SelectItem[] updateItems(String sql){
		ArrayList<HashMap<String, Object>> arr = ConnectDB.getDataTypeList(sql);
		 SelectItem[] arrItem = new SelectItem[arr.size() + 1];
		 arrItem[0] = new SelectItem("-1", "Tất cả");
		for (int i = 0; i < arr.size(); i++) {
			HashMap<String, Object> row = arr.get(i);
			arrItem[i + 1]  = new SelectItem(row.get("id"), (String) row.get("fullname"));
		}
		return arrItem;
	}
	
	/****************************************************
	 * Method name		: getLoGroups [GETTER]
	 * Return type		: List
	 * Decription		: trả vê ds các group trong DB
	 * Created date		: Jun 4, 2008
	 * Author			: Phonglt
	 ****************************************************/
	public SelectItem[]  getGroups() {
		return this.updateItems(sql_groups);
	}
	/****************************************************
	 * Method name		: getLoCats [GETTER]
	 * Return type		: List
	 * Decription		: trả vê ds các cat trong DB
	 * Created date		: Jun 4, 2008
	 * Author			: Phonglt
	 ****************************************************/
	public SelectItem[]  getCats() {
		return this.updateItems(this.sql_cats);
	}
	
	
}
